package com.allwees.bs.c.module.product.dto;

import com.allwees.bs.c.module.product.entity.SkuEntity;
import com.allwees.bs.core.model.product.entity.SkuModel;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * 商品SKU数据传输对象
 */
@NoArgsConstructor
//@ApiModel
public class SkuDTO extends SkuModel {
    public final static String[] ORDER_REVIEW_FIELDS = {"id", "productUuid", "color", "size"};
    private static final long serialVersionUID = -5107936260781958970L;

    protected String[] photos;

    public SkuDTO(SkuEntity sku) {
    	this(sku, true);
    }

    public SkuDTO(SkuEntity sku, boolean fullMode) {
        if (Objects.isNull(sku)) {
            return;
        }
        this.setUuid(sku.getUuid());
        this.setNo(sku.getValidNo());
        this.setColor(sku.getColor());
        this.setSize(sku.getSize());
        this.setQuantity(sku.getQuantity());
        this.setCurrency(sku.getCurrency());
        this.setOriginalPrice(sku.getOriginalPrice());
        this.setRetailPrice(sku.getRetailPrice());
        this.setShippingPrice(sku.getShippingPrice());
        if(fullMode) {
            this.setProductUuid(sku.getProductUuid());
            this.setStatus(sku.getStatus());
            this.setShippingCurrency(sku.getShippingCurrency());
            this.setCreatedAt(sku.getCreatedAt());
            this.setUpdatedAt(sku.getUpdatedAt());
            this.setDeletedAt(sku.getDeletedAt());
            String[] skuPhotos = sku.getPhotos();
            //可能没有图片，当SKU没有自己的图片时，使用商品的图片
//            if(ArrayUtils.isEmpty(skuPhotos)) {
//            	skuPhotos = BeanUtil.getBean(IProductService.class).findProductByUuid(sku.getProductUuid()).getPhotos();
//            }
            this.setPhotos(skuPhotos);
        }
    }

    public SkuDTO filter(boolean fullMode) {
        if(!fullMode) {
            this.setStatus(null);
            this.setCreatedAt(null);
            this.setUpdatedAt(null);
            this.setDeletedAt(null);
            this.setPhotos(null);
        }
        return this;
    }

	@Override
	public String[] getPhotos() {
		return super.getPhotos();
	}

	@Override
	public void setPhotos(String[] photos) {
		super.setPhotos(photos);
	}
}
